import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        fixShow:false,
        adminData:null,
        baseurl:'http://project.wangshangyuan.top/',
        page_size:10,
        // 登录
        loginData:null,
        oneData:null,
        // one
        oneData:null,
        oneShow:true,
        twoShow:false,
        oneitem:null,
        onecode:null,
        // two
        twoData:null,
        // 修改
        eitcode:null,

    },
    mutations: {
        updateData(state,obj){
            state[obj.selected] = obj.data;
            console.log(state[obj.selected]);
            state[obj.codekey] = obj.codevalue;
            console.log(state[obj.codekey]);
            console.log(obj.codekey);
        }
    },
    actions: {
        allData({commit}, obj){                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                var postParameobj = {}
                var getParameobj = {}
                if(obj.method.toUpperCase()==='POST' || obj.method.toUpperCase()==='PUT'){
                   postParameobj = obj.paramesdata
                }else{
                   getParameobj = obj.paramesdata
                }
                axios({
                    method:obj.method,
                    url:obj.url,
                    data:postParameobj,
                    params:getParameobj,
                }).then((res)=>{
                    commit('updateData',{selected:obj.selected,data:res.data.data,codekey:obj.code,codevalue:res.data.code})
                })
        }

    }
})